package com.blrs.service.project.schedule.impI;

import java.sql.Timestamp;
import java.util.*;

import com.blrs.common.utils.SecurityUtils;
import com.blrs.common.utils.StringUtils;
import com.blrs.domain.ProjectInfo;
import com.blrs.domain.ProjectStage;
import com.blrs.domain.SubProjectInfo;
import com.blrs.mapper.ProjectStageMapper;
import com.blrs.system.domain.SysUserPost;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.blrs.mapper.ProjectScheduleMapper;
import com.blrs.domain.ProjectSchedule;
import com.blrs.service.project.schedule.IProjectScheduleService;

import static org.apache.commons.lang3.StringUtils.split;

/**
 * 项目进度Service业务层处理
 * 
 * @author wangchao
 * @date 2023-12-01
 */
@Service
public class ProjectScheduleServiceImpl implements IProjectScheduleService 
{
    @Autowired
    private ProjectScheduleMapper projectScheduleMapper;
    @Autowired
    private ProjectStageMapper projectStageMapper;


    @Override
    public List<ProjectSchedule> selectProjectScheduleListMaxIndex(ProjectSchedule projectSchedule)
    {
        return projectScheduleMapper.selectProjectScheduleListMaxIndex(projectSchedule);
    }
    //获取阶段名称
    @Override
    public List<Map> getScheduleName(ProjectStage projectStage) {
        List<ProjectStage> fList=projectStageMapper.selectProjectStageList(projectStage);//阶段名称
        List<Map> list=new ArrayList<>();
        if(fList.size()==0){
            Map map=new HashMap<>();
            map.put("size",0);
        }else{
            for(ProjectStage infoStage : fList){
                Map map=new HashMap<>();
                if(infoStage.getState().equals("0")){
                    map.put("calssCss","yd-step-item");
                }else if(infoStage.getState().equals("1")){
                    map.put("calssCss","yd-step-item yd-step-item-current");
                }
                map.put("size",fList.size());
                map.put("state",infoStage.getState());
                map.put("value",infoStage.getName());
                map.put("label",infoStage.getName());//阶段名称
                map.put("stageId",fList.get(0).getId());
                map.put("projectId",fList.get(0).getProjectId());
                list.add(map);
            }
        }


        return list;
    }
    /**
     * 查询项目进度
     * 
     * @param id 项目进度主键
     * @return 项目进度
     */
    @Override
    public ProjectSchedule selectProjectScheduleById(String id)
    {
        return projectScheduleMapper.selectProjectScheduleById(id);
    }

    /**
     * 查询项目进度列表
     * 
     * @param projectSchedule 项目进度
     * @return 项目进度
     */
    @Override
    public List<ProjectSchedule> selectProjectScheduleList(ProjectSchedule projectSchedule)
    {
        return projectScheduleMapper.selectProjectScheduleList(projectSchedule);
    }

    /**
     * 新增项目进度
     * 
     * @param projectSchedule 项目进度
     * @return 结果
     */
    @Override
    public int insertProjectSchedule(ProjectSchedule projectSchedule)
    {
        //projectSchedule.setId(UUID.randomUUID().toString());
        projectSchedule.setCreationId(SecurityUtils.getUserId().toString());
        projectSchedule.setCreationName(SecurityUtils.getUsername());
        projectSchedule.setCreationTime(new Timestamp(new Date().getTime()));
        return projectScheduleMapper.insertProjectSchedule(projectSchedule);
    }

    /**
     * 修改项目进度
     * 
     * @param projectSchedule 项目进度
     * @return 结果
     */
    @Override
    public int updateProjectSchedule(ProjectSchedule projectSchedule)
    {
        projectSchedule.setCreationTime(projectSchedule.getCreationTime());
        return projectScheduleMapper.updateProjectSchedule(projectSchedule);
    }

    /**
     * 批量删除项目进度
     * 
     * @param ids 需要删除的项目进度主键
     * @return 结果
     */
    @Override
    public int deleteProjectScheduleByIds(String[] ids)
    {
        return projectScheduleMapper.deleteProjectScheduleByIds(ids);
    }

    /**
     * 删除项目进度信息
     * 
     * @param id 项目进度主键
     * @return 结果
     */
    @Override
    public int deleteProjectScheduleById(String id)
    {
        return projectScheduleMapper.deleteProjectScheduleById(id);
    }
}
